#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./esb/components/bk/apis/cc/get_process_port_by_ip.py
# Compiled at: 2017-11-16 15:44:28
"""
Copyright © 2012-2017 Tencent BlueKing. All Rights Reserved. 蓝鲸智云 版权所有
"""
from common.forms import BaseComponentForm, ListField
from common.constants import API_TYPE_Q
from components.component import Component
from .toolkit import tools, configs

class GetProcessPortByIp(Component):
    """[CC] 根据主机查询进程端口接口
    
    {% block api_doc %}
    
    描述
    ~~~~
    
    根据主机查询进程端口接口
    
    参数说明
    ~~~~~~~~
    
    {{ common_args_desc }}
    
    其他参数
    
    ===============  ======  ========  ================================================================
    参数名称         必须    类型      参数说明
    ===============  ======  ========  ================================================================
    ips              Y       string    IP地址，多个以逗号分隔
    ===============  ======  ========  ================================================================
    
    请求参数示例
    ~~~~~~~~~~~~
    
    .. code:: json
    
        {
            "ips": "10.0.0.1"
        }
    
    结果说明
    ~~~~~~~~
    
    .. code:: json
    
        {
            "result": true,
            "code": "00",
            "message": "",
            "data": [
                {
                    "InnerIP": "10.0.0.1",
                    "OuterIP": "",
                    "ApplicationID": "1",
                    "Source": "1",
                    "ApplicationName": "资源池",
                    "Process": []
                },
                {
                    "InnerIP": "10.0.0.1",
                    "OuterIP": "",
                    "ApplicationID": "2",
                    "Source": "1",
                    "ApplicationName": "数据平台测试",
                    "Process": []
                }
            ]
        }
    
    {% endblock %}
    """
    sys_name = configs.SYSTEM_NAME
    api_type = API_TYPE_Q

    class Form(BaseComponentForm):
        ips = ListField(label=u'IP列表', required=True)

        def clean(self):
            data = self.cleaned_data
            return {'ips': (',').join(data['ips'])
               }

    def handle(self):
        client = tools.CCClient(self.outgoing.http_client)
        self.response.payload = client.post_request(configs.host, '/api/process/getProcessPortByIP', data=self.form_data)
